#include "ts.h"


tsClass::tsClass(QWidget *parent) : JDialog(parent)
{
	QGridLayout *mainHLayout = new QGridLayout(this);
	QGridLayout *pSubLayout 	= new QGridLayout;
	QVBoxLayout *calibrateVBox 	= new QVBoxLayout;
	QVBoxLayout *testVBox 	= new QVBoxLayout;

	calibrateBt = new QPushButton;
	testBt = new QPushButton;

	QLabel *calibrateLb = new QLabel(this);
	QLabel *testLb = new QLabel(this);
	QFrame *pFrame = new QFrame(this);

	testLb->setAlignment(Qt::AlignCenter);
	calibrateLb->setAlignment(Qt::AlignCenter);

//	testLb->setStyleSheet("border: 1px solid  #ff0000");
//	calibrateLb->setStyleSheet("border: 1px solid  #ff0000");
	
	calibrateLb->setText("校准");
	testLb->setText("触摸测试");

	calibrateBt->setStyleSheet("border-image: url(:/image/linuxdesktop/settingsicon/touchcal_normal.png);");
	testBt->setStyleSheet("border-image: url(:/image/linuxdesktop/settingsicon/ts_test.png);");


	calibrateVBox->setSpacing(0);
	testVBox->setSpacing(0);

	
	calibrateVBox->addWidget(calibrateBt);
	calibrateVBox->addWidget(calibrateLb);

	
	testVBox->addWidget(testBt);
	testVBox->addWidget(testLb);
	
	
	testLb->setFixedSize(150, 20);
	calibrateLb->setFixedSize(150, 20);
	testBt->setFixedSize(150, 150);
	calibrateBt->setFixedSize(150, 150);

	process = new QProcess(this);

	connect(calibrateBt, SIGNAL(clicked()), this, SLOT(tsCalibrate()));
	connect(testBt, SIGNAL(clicked()), this, SLOT(tsTest()));



	pSubLayout->addLayout(calibrateVBox, 0,0,1,1);
	pSubLayout->addLayout(testVBox, 	 0,2,1,1);

 	pFrame->setLayout(pSubLayout);


//	mainHLayout->setAlignment(Qt::AlignCenter);
  	mainHLayout->addWidget(pFrame, 0, 0, 1, 1);
  //  mainHLayout->setContentsMargins(40, 15, 40, 15);
    
    pFrame->setObjectName("tsFrame");
    this->setJLayout(mainHLayout);
    this->setJTitle(tr("触摸屏"));
}
tsClass::~tsClass()
{


}


void tsClass::tsCalibrate()
{
	qDebug("tsCalibrate\n");

	process->start("ts_calibrate");

	process->waitForStarted();
	process->waitForFinished(-1);

	QWSServer::instance()->closeMouse();
	QWSServer::instance()->openMouse();
	this->update();
	
}

void tsClass::tsTest()
{
	qDebug("tsTest\n");

	process->start("ts_test");

	process->waitForStarted();
	process->waitForFinished(-1);

	this->update();
}